{include file='public/header' /}
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body table-tool-mini full-table">
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    {present name="account_lists"}
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">商&emsp;家：</label>
                        <div class="layui-input-inline">
                            <select id="account" name="account_id" lay-search>
                                {foreach $account_lists as $vo}
                                <option value="{$vo.id}">{$vo.name}</option>

                                {/foreach}

                                {/foreach}
                            </select>
                        </div>
                    </div>
                    {/present}

                    <div class="layui-inline" style="padding-right: 110px;">
                        <button class="layui-btn icon-btn" lay-filter="formSubSearchUser" lay-submit>
                            <i class="layui-icon">&#xe615;</i>搜索
                        </button>

                          </div>
                </div>
            </div>

            <table id="tableUser" lay-filter="tableUser"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="tableBarUser">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">查看记录</a>

</script>
    <script type="text/html" id="thumb">

        {{# if(d.avatar_url){ }}
        <a href="{{d.avatar_url}}" target="_blank" title="点击查看">
            <img src="{{d.avatar_url}}" alt="" width="28" height="28">
        </a>
        {{#  } }}
    </script>

<!-- js部分 -->
{include file='public/footer' /}
<!--<script src="__STATIC__/js/base64.js"></script>-->

<script>
    layui.use(['layer', 'form', 'table', 'util', 'admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;

        // 渲染表格
        var insTb = table.render({
            elem: '#tableUser',
            url: '{:__url("system.chat/getData")}',

            page: true,
            toolbar: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers'},
                {field: 'nick_name', sort: true, title: '用户名'},

                {title: '内容',templet:function(d){
                    //$a = $.base64.decode(d.content, 'utf8');
                    return d.content;
                }
                },

                {field: 'avatar_url', title: '图片',toolbar:'#thumb'},
                {
                    title: '类型', templet: function (d) {
                    var strs = ['','<span class="layui-badge layui-bg-blue">文本</span>',
                        '<span class="layui-badge layui-bg-green">表情</span>',
                        '<span class="layui-badge layui-bg-red">商品链接</span>',
                        '<span class="layui-badge layui-bg-red">自动回复</span>'];
                    return strs[d.msgtype];
                }, align: 'center'
                },
                {field: 'create_time', sort: true, title: '创建时间'},

                /* {field: 'state', sort: true, templet: '#tableStateUser', title: '状态'},*/
                {align: 'center', toolbar: '#tableBarUser', title: '操作', minWidth: 200}
            ]]
        });
        /*  var account_id = $("#account").val();
        table.render.reload({
            where: {account_id: account_id},
            page: {curr: 1}
        })*/
        // 添加
        $('#btnAddUser').click(function () {
            showEditModel();
        });

        // 搜索
        form.on('submit(formSubSearchUser)', function (data) {
            insTb.reload({where: data.field}, 'data');
        });

        // 工具条点击事件
        table.on('tool(tableUser)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'edit') { // 修改
                $account_id = $("#account").val();
                showEditModel('detail?to_id='+data.uid+'&from='+$account_id);
            }
        });

        // 显示表单弹窗
        function showEditModel(url) {

            //console.log(data.id);
            admin.open({
                type: 2,
                area:['500px','600px'],
                title: '查看记录',
                content: url,
                btnAlign: 'c',   // 按钮居中
                success: function (layero, dIndex) {
                    form.render();    // 表单渲染
                },



            });
        }



        //搜索
        $("#searchBtn").click(function () {
            var account_id = $("#account").val();
            dataTable.reload({
                where: {account_id: account_id},
                page: {curr: 1}
            })
        })




    });
</script>

</body>
</html>
